package com.tools.controller.workflow;

import com.tools.service.workflow.FlowEngineService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 步骤控制器
 */
@RestController
@RequestMapping("/step")
@RequiredArgsConstructor
public class StepController {

    private final FlowEngineService flowEngineService;
    /**
     * 测试订单处理流程
     */
    @PostMapping("/order-process")
    public Map<String, Object> testOrderProcess(@RequestBody Map<String, Object> requestData) {
        String businessKey = "ORDER_" + System.currentTimeMillis();

        Map<String, Object> initialData = new HashMap<>();
        initialData.put("businessData", requestData.get("orderData"));
        initialData.put("amount", requestData.get("amount"));
        initialData.put("customerId", requestData.get("customerId"));

        Long instanceId = flowEngineService.startFlow("ORDER_PROCESS", businessKey, initialData);
        flowEngineService.executeFlow(instanceId);

        Map<String, Object> result = new HashMap<>();
        result.put("success", true);
        result.put("instanceId", instanceId);
        result.put("businessKey", businessKey);
        result.put("message", "订单处理流程执行完成");

        return result;
    }
    /**
     * 查询流程实例状态
     */
    @GetMapping("/status/{instanceId}")
    public Map<String, Object> getFlowStatus(@PathVariable Long instanceId) {
        // 这里可以返回流程执行状态和详细步骤信息
        Map<String, Object> result = new HashMap<>();
        result.put("instanceId", instanceId);
        result.put("status", "查询功能待实现");
        return result;
    }

}
